package com.demo2do.fms.entity.business.shipment;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.format.annotation.DateTimeFormat;

/**
 * 派车单
 * 
 * @author Ysy
 *
 */
@Entity
@Table(name = "TBL_TRUCK_DISPATCH_ORDER")
public class DispatchOrder {
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** 派车单号  */
    @Column(name = "DISPATCH_ORDER_CODE")
    private String code;
    
    /** 派车单时间  */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date dispatchDate;
    
    /** 安吉调度指令组号  */
    private String shipmentGroupId;
    
    /** 调度数量(商品车数量)  */
    private Integer actualLoadNumber;
    
    /** 装载能力  */
    private Integer fullLoadNumber;
    
    /** 行驶公里数 */
    private BigDecimal facilityDistance;
    
    /** 默认行驶公里数 */
    private BigDecimal facilityDistanceDefault;
    
    /** 行驶公里数调整类型 */
    private String distanceAdjustType;
    
    /** 行驶公里数调整理由补充 */
    private String distanceAdjustRemark;
    
    /** 是否回单  */
    @Column(name = "IS_ACCOMPLISH_CONFIRM")
    private Boolean accomplishConfirm;
    
    /** 回单数量  */
    private Integer accomplishConfirmNumber;
    
    /** 是否打印报销  */
    @Column(name = "IS_EXPENSE_PRINT")
    private Boolean expensePrint;
    
    /** 打印日期 */
    private Date expensePrintDate;
    
    /** 打印人 */
    private Long expensePrintUser;
    
    /** 是否报销  */
    @Column(name = "IS_EXPENSE_REIMBURSED")
    private Boolean expenseReimbursed;
    
    /** 报销号 */
    private String reimburseCode;
    
    /** 报销日期  */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date expenseReimburseDate;
    
    /** 报销人 */
    private Long expenseReimburseUser;
    
    /** 起始装卸地  */
    private Long startFacilityId;
    
    /** 目的装卸地 */
    private Long destinationFacilityId;
    
    /** 驳运车ID  */
    private Long vehicleId;
    
    /** 主驾驶员  */
    private Long mainDriverId;
    
    /** 第一副驾驶员  */
    private Long firstViceDriverId;
    
    /** 驾驶员数量 */
    private Integer driverNumber;
    
    /** 所属公司  */
    private Long organizationId;
    
    /** 创建人 */
    private Long creatorId;
    
    /** 创建时间 */
    private Date createDate;
    
    /** 备注 */
    private String remarks;
    
    /** 离开时间*/
    private Date leavingTime;
    
    /** 最后修改时间 */
    private Date lastModifyDate;
    
    /** 最后修改人 */
    private Long lastOperatorId;
    
    /** 是否启用  */
    @Column(name = "is_disabled")
    private Boolean disabled;
    
    /**
     * the default constructor
     */
    public DispatchOrder() {
    }
    
    /**
     * 
     * @param id
     * @param organizationId
     * @param shipmentGroupId
     * @param startFacilityId
     * @param destinationFacilityId
     * @param vehicleId
     * @param mainDriverId
     * @param firstViceDriverId
     * @param facilityDistance
     * @param fullLoadNumber
     */
    public DispatchOrder(Long id, Long organizationId, String shipmentGroupId, Long startFacilityId, Long destinationFacilityId, Long vehicleId, 
            Long mainDriverId, Long firstViceDriverId, BigDecimal facilityDistance, Integer fullLoadNumber) {
        this.id = id;
        this.organizationId = organizationId;
        this.shipmentGroupId = shipmentGroupId;
        this.startFacilityId = startFacilityId;
        this.destinationFacilityId = destinationFacilityId;
        this.vehicleId = vehicleId;
        this.mainDriverId = mainDriverId;
        this.firstViceDriverId = firstViceDriverId;
        this.facilityDistance = facilityDistance;
        this.fullLoadNumber = fullLoadNumber;
    }
    
    /**
     * 回单确认(更新派车单回单数量)
     * 
     * @param accomplishConfirmNumber
     * @param lastOperatorId
     * @param lastModifyDate
     * @return
     */
    public DispatchOrder accomplishConfirm(Integer accomplishConfirmNumber, Long lastOperatorId, Date lastModifyDate) {
        this.accomplishConfirmNumber = accomplishConfirmNumber;
        // this.lastOperatorId = lastOperatorId;
        this.lastModifyDate = lastModifyDate;
        return this;
    }
    
    /**
     * 回单完成
     * 
     * @param lastOperatorId
     * @param lastModifyDate
     * @return
     */
    public DispatchOrder finish(Long lastOperatorId, Date lastModifyDate) {
        this.accomplishConfirm = true;
        // this.lastOperatorId = lastOperatorId;
        this.lastModifyDate = lastModifyDate;
        return this;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public boolean hasAccomplishComfirmed() {
        return this.actualLoadNumber > 0 && this.accomplishConfirmNumber > 0;
    }
    
    /**
     * 是否是全部回单
     * 
     * @return
     */
    @Transient
    public boolean isAllAccomplishConfirmed() {
        return this.accomplishConfirmNumber == this.actualLoadNumber;
    }
    
    /**
     * @return
     */
    @Transient
    public boolean isEmptyDispatch() {
        return this.actualLoadNumber == 0;
    }
    
    /**
     * 
     * @param code
     */
    public void editCode(String code){
        this.code = code;
    }
    
    /**
     * @return
     */
    public Boolean disabled() {
        return this.disabled;
    }
    
    /**
     * @return
     */
    public Boolean reimbursed() {
        return this.expenseReimbursed;
    }
    
    /**
     * @param expenseReimburseUser
     * @param expenseReimburseDate
     * @return
     */
    public DispatchOrder reimburse(Long expenseReimburseUser, Date expenseReimburseDate) {
        this.expenseReimbursed = true;
        this.expenseReimburseUser = expenseReimburseUser;
        this.expenseReimburseDate = expenseReimburseDate;
        return this;
    }
    
    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the dispatchDate
     */
    public Date getDispatchDate() {
        return dispatchDate;
    }

    /**
     * @return the shipmentGroupId
     */
    public String getShipmentGroupId() {
        return shipmentGroupId;
    }

    /**
     * @return the actualLoadNumber
     */
    public Integer getActualLoadNumber() {
        return actualLoadNumber;
    }

    /**
     * @return the fullLoadNumber
     */
    public Integer getFullLoadNumber() {
        return fullLoadNumber;
    }

    /**
     * @return the facilityDistance
     */
    public BigDecimal getFacilityDistance() {
        return facilityDistance;
    }

    /**
     * @return the facilityDistanceDefault
     */
    public BigDecimal getFacilityDistanceDefault() {
        return facilityDistanceDefault;
    }

    /**
     * @return the distanceAdjustType
     */
    public String getDistanceAdjustType() {
        return distanceAdjustType;
    }

    /**
     * @return the distanceAdjustRemark
     */
    public String getDistanceAdjustRemark() {
        return distanceAdjustRemark;
    }

    /**
     * @return the accomplishConfirm
     */
    public Boolean getAccomplishConfirm() {
        return accomplishConfirm;
    }

    /**
     * @return the accomplishConfirmNumber
     */
    public Integer getAccomplishConfirmNumber() {
        return accomplishConfirmNumber;
    }

    /**
     * @return the expensePrint
     */
    public Boolean getExpensePrint() {
        return expensePrint;
    }

    /**
     * @return the expensePrintDate
     */
    public Date getExpensePrintDate() {
        return expensePrintDate;
    }

    /**
     * @return the expensePrintUser
     */
    public Long getExpensePrintUser() {
        return expensePrintUser;
    }

    /**
     * @return the expenseReimbursed
     */
    public Boolean getExpenseReimbursed() {
        return expenseReimbursed;
    }

    /**
     * @return the reimburseCode
     */
    public String getReimburseCode() {
        return reimburseCode;
    }

    /**
     * @return the expenseReimburseDate
     */
    public Date getExpenseReimburseDate() {
        return expenseReimburseDate;
    }

    /**
     * @return the expenseReimburseUser
     */
    public Long getExpenseReimburseUser() {
        return expenseReimburseUser;
    }

    /**
     * @return the startFacilityId
     */
    public Long getStartFacilityId() {
        return startFacilityId;
    }

    /**
     * @return the destinationFacilityId
     */
    public Long getDestinationFacilityId() {
        return destinationFacilityId;
    }

    /**
     * @return the vehicleId
     */
    public Long getVehicleId() {
        return vehicleId;
    }

    /**
     * @return the mainDriverId
     */
    public Long getMainDriverId() {
        return mainDriverId;
    }

    /**
     * @return the firstViceDriverId
     */
    public Long getFirstViceDriverId() {
        return firstViceDriverId;
    }

    /**
     * @return the driverNumber
     */
    public Integer getDriverNumber() {
        return driverNumber;
    }

    /**
     * @return the organizationId
     */
    public Long getOrganizationId() {
        return organizationId;
    }

    /**
     * @return the creatorId
     */
    public Long getCreatorId() {
        return creatorId;
    }
    
    /**
     * @return
     */
    public Date getCreateDate() {
        return createDate;
    }

    /**
     * @return the remarks
     */
    public String getRemarks() {
        return remarks;
    }

    /**
     * @return the leavingTime
     */
    public Date getLeavingTime() {
        return leavingTime;
    }

    /**
     * @return the lastModifyDate
     */
    public Date getLastModifyDate() {
        return lastModifyDate;
    }

    /**
     * @return the lastOperatorId
     */
    public Long getLastOperatorId() {
        return lastOperatorId;
    }

    /**
     * @return the disabled
     */
    public Boolean getDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param dispatchDate the dispatchDate to set
     */
    public void setDispatchDate(Date dispatchDate) {
        this.dispatchDate = dispatchDate;
    }

    /**
     * @param shipmentGroupId the shipmentGroupId to set
     */
    public void setShipmentGroupId(String shipmentGroupId) {
        this.shipmentGroupId = shipmentGroupId;
    }

    /**
     * @param actualLoadNumber the actualLoadNumber to set
     */
    public void setActualLoadNumber(Integer actualLoadNumber) {
        this.actualLoadNumber = actualLoadNumber;
    }

    /**
     * @param fullLoadNumber the fullLoadNumber to set
     */
    public void setFullLoadNumber(Integer fullLoadNumber) {
        this.fullLoadNumber = fullLoadNumber;
    }

    /**
     * @param facilityDistance the facilityDistance to set
     */
    public void setFacilityDistance(BigDecimal facilityDistance) {
        this.facilityDistance = facilityDistance;
    }

    /**
     * @param facilityDistanceDefault the facilityDistanceDefault to set
     */
    public void setFacilityDistanceDefault(BigDecimal facilityDistanceDefault) {
        this.facilityDistanceDefault = facilityDistanceDefault;
    }

    /**
     * @param distanceAdjustType the distanceAdjustType to set
     */
    public void setDistanceAdjustType(String distanceAdjustType) {
        this.distanceAdjustType = distanceAdjustType;
    }

    /**
     * @param distanceAdjustRemark the distanceAdjustRemark to set
     */
    public void setDistanceAdjustRemark(String distanceAdjustRemark) {
        this.distanceAdjustRemark = distanceAdjustRemark;
    }

    /**
     * @param accomplishConfirm the accomplishConfirm to set
     */
    public void setAccomplishConfirm(Boolean accomplishConfirm) {
        this.accomplishConfirm = accomplishConfirm;
    }

    /**
     * @param accomplishConfirmNumber the accomplishConfirmNumber to set
     */
    public void setAccomplishConfirmNumber(Integer accomplishConfirmNumber) {
        this.accomplishConfirmNumber = accomplishConfirmNumber;
    }

    /**
     * @param expensePrint the expensePrint to set
     */
    public void setExpensePrint(Boolean expensePrint) {
        this.expensePrint = expensePrint;
    }

    /**
     * @param expensePrintDate the expensePrintDate to set
     */
    public void setExpensePrintDate(Date expensePrintDate) {
        this.expensePrintDate = expensePrintDate;
    }

    /**
     * @param expensePrintUser the expensePrintUser to set
     */
    public void setExpensePrintUser(Long expensePrintUser) {
        this.expensePrintUser = expensePrintUser;
    }

    /**
     * @param expenseReimbursed the expenseReimbursed to set
     */
    public void setExpenseReimbursed(Boolean expenseReimbursed) {
        this.expenseReimbursed = expenseReimbursed;
    }

    /**
     * @param reimburseCode the reimburseCode to set
     */
    public void setReimburseCode(String reimburseCode) {
        this.reimburseCode = reimburseCode;
    }

    /**
     * @param expenseReimburseDate the expenseReimburseDate to set
     */
    public void setExpenseReimburseDate(Date expenseReimburseDate) {
        this.expenseReimburseDate = expenseReimburseDate;
    }

    /**
     * @param expenseReimburseUser the expenseReimburseUser to set
     */
    public void setExpenseReimburseUser(Long expenseReimburseUser) {
        this.expenseReimburseUser = expenseReimburseUser;
    }

    /**
     * @param startFacilityId the startFacilityId to set
     */
    public void setStartFacilityId(Long startFacilityId) {
        this.startFacilityId = startFacilityId;
    }

    /**
     * @param destinationFacilityId the destinationFacilityId to set
     */
    public void setDestinationFacilityId(Long destinationFacilityId) {
        this.destinationFacilityId = destinationFacilityId;
    }

    /**
     * @param vehicleId the vehicleId to set
     */
    public void setVehicleId(Long vehicleId) {
        this.vehicleId = vehicleId;
    }

    /**
     * @param mainDriverId the mainDriverId to set
     */
    public void setMainDriverId(Long mainDriverId) {
        this.mainDriverId = mainDriverId;
    }

    /**
     * @param firstViceDriverId the firstViceDriverId to set
     */
    public void setFirstViceDriverId(Long firstViceDriverId) {
        this.firstViceDriverId = firstViceDriverId;
    }

    /**
     * @param driverNumber the driverNumber to set
     */
    public void setDriverNumber(Integer driverNumber) {
        this.driverNumber = driverNumber;
    }

    /**
     * @param organizationId the organizationId to set
     */
    public void setOrganizationId(Long organizationId) {
        this.organizationId = organizationId;
    }

    /**
     * @param creatorId the creatorId to set
     */
    public void setCreatorId(Long creatorId) {
        this.creatorId = creatorId;
    }
    
    /**
     * @param createDate
     */
    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    /**
     * @param remarks the remarks to set
     */
    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    /**
     * @param leavingTime the leavingTime to set
     */
    public void setLeavingTime(Date leavingTime) {
        this.leavingTime = leavingTime;
    }

    /**
     * @param lastModifyDate the lastModifyDate to set
     */
    public void setLastModifyDate(Date lastModifyDate) {
        this.lastModifyDate = lastModifyDate;
    }

    /**
     * @param lastOperatorId the lastOperatorId to set
     */
    public void setLastOperatorId(Long lastOperatorId) {
        this.lastOperatorId = lastOperatorId;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }
}
